<template>
	<view class="myAuction">
		<!-- <header-box :title="pageTitle"></header-box> -->
		<view class="fixed-box">
			<view class="switch-box">
				<view :class="['item',type == 0 ? 'active' : '']" @tap="switchFun(0)">待支付</view>
				<view :class="['item',type == 1 ? 'active' : '']" @tap="switchFun(1)">竞拍中</view>
				<view class="line" :style="{left:lineLift}"></view>
			</view>
		</view>
		<view class="myAuction-box">
			<mescroll-uni ref="mescrollRef" :isBack="true" @init="mescrollInit" height="" :top="mescrollUni_Top" :bottom="mescrollUniBottom" :total="total" :down="downOption" @down="downCallback" :up="upOption" @up="upCallback" @emptyclick="emptyClick">
				<view class="myAuction-main">
					<view class="_main-item" @click="toAuctionDetail(item)" v-for="item,index in list" :key="index">
						<view class="_main-item-goods"><image class="_main-item-goods-img" :src="item.auctionImg" mode=""></image></view>
						
						<!-- 待支付 -->
						<view class="_main-item-info" v-if="type == 0">
							<view class="_main-item-title"><text>{{item.name}}</text><text class="_main-item-money">￥{{item.myPrice}}</text></view>
							<view class="_main-item-endTime"><text>结束时间:{{timeFunc(item.endTime)}}</text></view>
							<view class="_main-item-pay" @click.stop="toPay(item)"><text>去支付</text></view>
						</view>
						<!-- 竞拍中 -->
						<view class="_main-item-info" v-else>
							<view class="_main-item-title"><text>{{item.name}}</text></view>
							<view class="_main-item-text"><text>当前出价：</text><text class="_main-item-text-money">￥{{item.currentPrice}}</text></view>
							<view class="_main-item-text"><text>我的出价：</text><text class="_main-item-text-money">￥{{item.myPrice}}</text></view>
							<view class="_main-item-endTime"><text>结束时间:{{item.endTime}}</text></view>
						</view>
					</view>
				</view>
			</mescroll-uni>
		</view>
	</view>
</template>

<script>
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	import MescrollMoreItemMixin from "@/components/mescroll-uni/mixins/mescroll-more-item.js";
	export default {
		mixins: [MescrollMixin,MescrollMoreItemMixin], // 注意此处还需使用MescrollMoreItemMixin (必须写在MescrollMixin后面)
		data() {
			return {
				type:0,//0待支付 1竞拍中,
				pageTitle:'我的竞拍',
				total:0,
				list:[],
				orderListParams:{
					page:1,
					pageSize:8,
					myAuctionType:0, // 0待支付  1竞拍中
				},
				downOption:{
					auto:false // 不自动加载 (mixin已处理第一个tab触发downCallback)
				},
				upOption:{
					auto:false, // 不自动加载
					page: {
						num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
						size: 10 // 每页数据的数量
					},
					noMoreSize: 6, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
					toTop:{
						offset:400,
					},
					empty:{
						tip: '~ 空空如也 ~', // 提示
						btnText: ''
					},
					elItem:{
						top:256,
						height:265,
						rowNum:2,
					}
				},
				mescrollUni_Top:86,
				mescrollUniBottom:0,
			};
		},
		computed: {
			lineLift() {
				return 100/3.8*(this.type + 1) - 100/(3.8*2) + '%'
			},
			timeFunc() {
				return (e) => {
					if (e) {
						let _e = this.$util.timestampToTime(e);
						return _e;
					} else {
						return ''
					}
				}
			}
		},
		onLoad(option) {
			if (option.type && option.type == 2) {
				this.type = 1;
			} else {
				this.type = 0;
			}
		},
		mounted() {
			this.switchFun(this.type)
			// this.mescroll.setPageNum(1)
			// this.mescroll.resetUpScroll(true)
			// this.mescroll.scrollTo(0,300)
		},
		methods:{
			//搜索类型
			switchFun(type){
				this.type = type
				this.orderListParams.myAuctionType = type; 
				this.mescroll.setPageNum(1)
				this.mescroll.resetUpScroll(true)
				this.mescroll.scrollTo(0,300)
			},
			/*下拉刷新的回调 */
			downCallback() {
				// 这里加载你想下拉刷新的数据, 比如刷新轮播数据
				// loadSwiper();
				// 下拉刷新的回调,默认重置上拉加载列表为第一页 (自动执行 page.num=1, 再触发upCallback方法 )
				this.mescroll.resetUpScroll()
			},
			/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
			upCallback(page) {
				// console.log(page.num)
				// this.orderListParams.currentPage = page.num
				this.getList()
			},
			//点击空布局按钮的回调
			emptyClick(){
				uni.showToast({
					title:'点击了按钮,具体逻辑自行实现'
				})
			},
			//获取订单列表
			getList(){
				this.mescroll.lockUpScroll(true)
				this.$api.myAuction(this.orderListParams).then(res => {
					console.log(res)
					let curLen = this.list.length
					let totalPage
					if(res.code == 200){
						if(this.orderListParams.page == 1) this.list = []
						this.list = this.list.concat(res.data.records)
						curLen = this.list.length
						totalPage = Math.ceil(res.data.total / this.orderListParams.pageSize)
						setTimeout(() => {
							this.mescroll.endByPage(curLen, totalPage);
						},200)
						this.total = res.data.total
					}
					// console.log(this.upOption.toTop)
					// this.mescroll.endSuccess(curLen)
					setTimeout(() => {
						this.mescroll.lockUpScroll(false)
					},800)
				},err => {
					setTimeout(() => {
						this.mescroll.lockUpScroll(false)
					},800)
					this.mescroll.endErr()
				})
			},
			toAuctionDetail(item) {
				uni.navigateTo({
					url:`/pages/auctionDetail/auctionDetail?auctionId=${item.auctionId}`
				})
			},
			toPay(item) {
				// type 2 拍卖
				uni.navigateTo({
					url:`/pages/cashier/cashier?type=2&price=${item.myPrice}&auctionId=${item.auctionId}&orderNo=${item.orderNo}`
				})
			}
		}
	}
</script>

<style lang="less">
	.myAuction{
		width: 100%;
		min-height: 100vh;
		background-color: #16181D;
		font-family: PingFangSC-Medium, PingFang SC, '微软雅黑';
		font:caption;
		display: flow-root;
		.fixed-box{
			position: fixed;
			// top: var(--window-top);
			// top:88rpx;
			top:0rpx;
			z-index: 999;
			left: 0;
			width: 100%;
			.switch-box{
				display: flex;
				height:87rpx;
				line-height: 87rpx;
				font-size: 32rpx;
				background: #16181D;
				position: relative;
				.item{
					// width: 33.3%;
					width: 26.6%;
					color: #5E6272;
					text-align: center;
				}
				.line{
					position: absolute;
					width:64rpx;
					height:4rpx;
					background:rgba(255,255,255,1);
					left: 50%;
					bottom: 0;
					transform: translateX(-50%);
					transition: left .3s;
				}
				.active{
					color: #ffffff;
					position: relative;
				}
			}
		}
		.myAuction-box{
			width: 100%;
			margin-top: 87rpx;
			.myAuction-main{
				padding: 0 32rpx;
				box-sizing: border-box;
				._main-item{
					margin-top: 32rpx;
					width: 100%;
					background: #262A34;
					border-radius: 40rpx;
					padding: 32rpx;
					box-sizing: border-box;
					display: flex;
					flex-wrap: nowrap;
					justify-content: flex-start;
					align-items: center;
					._main-item-goods{
						width: 214rpx;
						height: 214rpx;
						border-radius: 40rpx;
						overflow: hidden;
						._main-item-goods-img{
							width: 100%;
							height: 100%;
						}
					}
					._main-item-info{
						width: calc(100% - 246rpx);
						margin-left: 32rpx;
						._main-item-title{
							font-size: 32rpx;
							font-weight: 400;
							color: #FFFFFF;
							display: flex;
							align-items: center;
							margin-bottom: 20rpx;
						}
						._main-item-money{
							font-size: 36rpx;
							font-family: Helvetica;
							color: #A06AF9;
							margin-left: 16rpx;
						}
						._main-item-endTime{
							font-size: 26rpx;
							font-weight: 400;
							color: #5D5F7A;
						}
						._main-item-pay{
							width: 196rpx;
							height: 64rpx;
							background: linear-gradient(223deg, #A339D8 0%, #6948F2 100%);
							border-radius: 32rpx;
							font-size: 28rpx;
							font-weight: 500;
							color: #FFFFFF;
							line-height: 64rpx;
							text-align: center;
							margin-top: 40rpx;
						}
						._main-item-text{
							font-size: 28rpx;
							font-weight: 400;
							color: #FFFFFF;
							display: flex;
							align-items: center;
							margin-bottom: 8rpx;
						}
						._main-item-text-money{
							color: #9D7DFF;
						}
					}
				}
			}
		}
	}
</style>
